﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using OpenSoftStore.BusinessLogic.Common;
using OpenSoftStore.BusinessLogic.Set;
using OpenSoftStore.Client.Common;
using OpenSoftStore.Client.UIL.ManageService;
using OpenSoftStore.Orm.Model;

namespace OpenSoftStore.Client.UIL.ManageSet
{
    public partial class SetList : UserControl
    {
        private static SetList instance;
        private TreeLogic lgcTree;
        /// <summary>
        /// 返回一个该控件的实例。如果之前该控件已经被创建，直接返回已创建的控件。
        /// 此处采用单键模式对控件实例进行缓存，避免因界面切换重复创建和销毁对象。
        /// </summary>
        public static SetList Instance
        {
            get
            {
                if (instance == null)
                {
                    instance = new SetList();
                }
                //BindDataGrid(); // 每次返回该控件的实例前，都将对DataGridView控件的数据源进行重新绑定。
                return instance;
            }
        }

        public SetList()
        {
            InitializeComponent();
            this.Dock = DockStyle.Fill;
            tvSet.ExpandAll();
            pnlContainer.Controls.Clear();
            pnlContainer.Controls.Add(ShopList.Instance);
            ShopList.Instance.Dock = DockStyle.Fill;

            if (!SysPowerManager.IsHavePower(SysPowerManager.门店信息设置))
            {
            }
            if (!SysPowerManager.IsHavePower(SysPowerManager.局域网数据源配置))
            {
            }
            if (!SysPowerManager.IsHavePower(SysPowerManager.数据备份_数据还原))
            {
            }
            if (!SysPowerManager.IsHavePower(SysPowerManager.连锁规则设置))
            {
            }
            if (!SysPowerManager.IsHavePower(SysPowerManager.软件在线升级设置))
            {
            }
            if (!SysPowerManager.IsHavePower(SysPowerManager.业务规则设置))
            {
            }
            if (!SysPowerManager.IsHavePower(SysPowerManager.客户积分规则设置))
            {
            }
            if (!SysPowerManager.IsHavePower(SysPowerManager.基础数据导入))
            {
            }
            if (!SysPowerManager.IsHavePower(SysPowerManager.打印设置))
            {
            }
        }



        private void toolStripButton1_Click(object sender, EventArgs e)
        {

        }

        private void trTree_AfterSelect(object sender, TreeViewEventArgs e)
        {
            if (tvSet.SelectedNode.Text == "门店信息设置")
            {
                pnlContainer.Controls.Clear();
                pnlContainer.Controls.Add(ShopList.Instance);
                ShopList.Instance.Dock = DockStyle.Fill;
            }
            else if (tvSet.SelectedNode.Text == "数据备份、还原")
            {
                pnlContainer.Controls.Clear();
                pnlContainer.Controls.Add(DataBaseSet.Instance);
                DataBaseSet.Instance.Dock = DockStyle.Fill;
            }
            else if (tvSet.SelectedNode.Text == "系统数据处理")
            {
                pnlContainer.Controls.Clear();
                pnlContainer.Controls.Add(SystemDataEdit.Instance);
                SystemDataEdit.Instance.Dock = DockStyle.Fill;
            }
            else if (tvSet.SelectedNode.Text == "业务规则设置")
            {
                pnlContainer.Controls.Clear();
                pnlContainer.Controls.Add(LogicSet.Instance);
                LogicSet.Instance.Dock = DockStyle.Fill;
            }
            else if (tvSet.SelectedNode.Text == "系统信息设置")
            {
                pnlContainer.Controls.Clear();
                pnlContainer.Controls.Add(SystemInfoSet.Instance);
                SystemInfoSet.Instance.Dock = DockStyle.Fill;
            }
            else if (tvSet.SelectedNode.Text == "打印设置")
            {
                pnlContainer.Controls.Clear();
                pnlContainer.Controls.Add(PrintSet.Instance);
                PrintSet.Instance.Dock = DockStyle.Fill;
            }
        }
    }
}
